package com.huaxiafinance.management.controller;

import com.huaxiafinance.management.dto.request.trialDto;
import com.huaxiafinance.management.service.TrialService;
import com.huaxiafinance.management.util.MessageResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


@Controller("customersTrialController")
@RequestMapping("/customersTrialController")
public class CustomersTrialController {
    protected Logger logger = Logger.getLogger(CustomersTrialController.class);
    @Autowired
    private TrialService trialService;

    /**
     * 查询所有用户
     *
     * @return
     */
    @RequestMapping(value = "/queryAllCustomers", produces = "application/json; charset=utf-8")
    public @ResponseBody String queryAllCustomers(@Valid @ModelAttribute("dto") trialDto dto){
        MessageResult messageResult=new MessageResult();
        try{
            messageResult = trialService.queryAllCustomers(dto);
        }catch (Exception e){
            messageResult.setFailureResult();
            logger.info("查询所有用户异常原因："+e);
        }
        logger.info("查询所有用户返回参数："+messageResult.getAsJSON());
        return messageResult.getAsJSON();
    }

    /**
     * 修改用户白名单
     *
     * @return
     */
    @RequestMapping(value = "/updateUser", produces = "application/json; charset=utf-8")
    public @ResponseBody String updateUser(HttpServletRequest request){
        MessageResult messageResult=new MessageResult();
        String userUuid = request.getParameter("userUuid");
        //1-试用用户 0-不是试用用户
        Integer type = Integer.parseInt(request.getParameter("type"));
        try{
            messageResult = trialService.updateUser(userUuid,type);
        }catch (Exception e){
            messageResult.setFailureResult();
            logger.info("修改用户白名单异常原因："+e);
        }
        logger.info("修改用户白名单返回参数："+messageResult.getAsJSON());
        return messageResult.getAsJSON();
    }



}
